﻿using System;
using System.Collections.Generic;
using System.Data;

using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client; 
//using Oracle.DataAccess.Types;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Oracle;

namespace DBQuery
{
    /// <summary>
    /// Summary description for ICPAdminTable
    /// </summary>
    public static class ICPAdminTable
    {

        public static int SaveAsAdmin(String sxICPUserId)
        {
        	DBLib dbl = new DBLib();
            int iReturn = SaveAsAdmin(dbl, sxICPUserId);
            
            return iReturn;
        }
        public static int SaveAsAdmin(DBLib dbl, String sxICPUserId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "out_new_id";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Direction = ParameterDirection.Output;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_ICP_USER_ID";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxICPUserId;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_CREATE_BY";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = ICPUser.ID;

            String sxQuery = "PR_INSERT_ICP_ADMIN";

            dbl.ExecuteProcedure(sxQuery, lsParams.ToArray());            
            return Convert.ToInt32(lsParams[0].Value);
        }

        public static void DeleteAdmin(int iAdminICPId)
        {
        	DBLib dbl = new DBLib();
            DeleteAdmin(dbl, iAdminICPId);
            
        }
        public static void DeleteAdmin(DBLib dbl, int iAdminICPId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            OracleParameter param = new OracleParameter();
            param.ParameterName = "prmID";
            param.OracleDbType = OracleDbType.Number;
            param.Value = iAdminICPId;

            String sxQuery = " delete from ICP_ADMIN where ICP_ADMIN_ID = :prmID";

            dbl.ExecuteNonQuery(sxQuery, param);            
        }
    }
}